package cn.fintecher.pangolin.service.business.model.request;

import cn.fintecher.pangolin.common.enums.FlowType;
import cn.fintecher.pangolin.entity.mysql.QFlowConfiguration;
import com.querydsl.core.BooleanBuilder;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

@Data
public class FlowConfigSearchRequest {

    @ApiModelProperty(notes = "配置名称")
    private String configName;

    @ApiModelProperty(notes = "申请类型")
    private FlowType flowType;

    public BooleanBuilder generateBooleanBuilder(){
        BooleanBuilder booleanBuilder = new BooleanBuilder();
        if(StringUtils.isNotBlank(configName)){
            booleanBuilder.and(QFlowConfiguration.flowConfiguration.configName.like(StringUtils.join(configName,"%")));
        }
        if(Objects.nonNull(flowType)){
            booleanBuilder.and(QFlowConfiguration.flowConfiguration.flowType.eq(flowType));
        }
        return booleanBuilder;
    }
}
